package com.tunnel.home.rest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.axe.annotation.ioc.Autowired;
import org.axe.annotation.ioc.Controller;
import org.axe.annotation.mvc.FilterFuckOff;
import org.axe.annotation.mvc.Request;
import org.axe.annotation.mvc.RequestParam;
import org.axe.bean.mvc.Param;
import org.axe.bean.mvc.View;
import org.axe.constant.RequestMethod;
import org.axe.home.rest.AxeRest;

import com.tunnel.home.common.SysConfig;

@FilterFuckOff
@Controller(basePath="",desc="访问页面")
public class HtmlRest {
	@Autowired
	private AxeRest axeRest;

	@Request(path = "", method = RequestMethod.GET, desc = "")
	public View root() {
		return new View("/index.html");
	}
	
	/**
	 * 静态资源
	 */
	@Request(path = "/{static_resource}", method = RequestMethod.GET, desc = "./")
	public void static_resource(
			@RequestParam(name = "static_resource", required = true, desc = "静态资源+路径") String static_resource,
			Param param, HttpServletRequest request, HttpServletResponse response) {
		/*if(StringUtil.isEmpty(SysConfig.html_dir())){
			//线上暂时不开放
			List<FormParam> list = new ArrayList<>();
			FormParam formParam = new FormParam("msg", "非常抱歉，网站正在申请备案中，备案完成就会开放...");
			list.add(formParam);
			axeRest.outputResource(response, SysConfig.html_dir()+"html/sorry.html", list);
			return;
		}*/
		axeRest.outputResource(response, SysConfig.html_dir()+"html/"+ static_resource, param.getFormParamList());
	}

	@Request(path = "/css/{static_resource}", method = RequestMethod.GET, desc = "./css/")
	public void css(@RequestParam(name = "static_resource", required = true, desc = "静态资源+路径") String static_resource,
			Param param, HttpServletRequest request, HttpServletResponse response) {
		axeRest.outputResource(response, SysConfig.html_dir()+"html/css/" + static_resource, param.getFormParamList());
	}

	@Request(path = "/images/{static_resource}", method = RequestMethod.GET, desc = "目录：./images/")
	public void images(@RequestParam(name = "static_resource", required = true, desc = "静态资源+路径") String static_resource,
			Param param, HttpServletRequest request, HttpServletResponse response) {
//		axeRest.outputResource(response, "com/gudidai/html/image/" + static_resource, param.getFormParamList());
		axeRest.outputResource(response, SysConfig.html_dir()+"html/images/" + static_resource, param.getFormParamList());
	}

	@Request(path = "/js/{static_resource}", method = RequestMethod.GET, desc = "目录：./js/")
	public void js(@RequestParam(name = "static_resource", required = true, desc = "静态资源+路径") String static_resource,
			Param param, HttpServletRequest request, HttpServletResponse response) {
//		axeRest.outputResource(response, "com/gudidai/html/image/" + static_resource, param.getFormParamList());
		axeRest.outputResource(response, SysConfig.html_dir()+"html/js/" + static_resource, param.getFormParamList());
	}
	

	@Request(path = "/fonts/{static_resource}", method = RequestMethod.GET, desc = "目录：./fonts/")
	public void fonts(@RequestParam(name = "static_resource", required = true, desc = "静态资源+路径") String static_resource,
			Param param, HttpServletRequest request, HttpServletResponse response) {
//		axeRest.outputResource(response, "com/gudidai/html/image/" + static_resource, param.getFormParamList());
		axeRest.outputResource(response, SysConfig.html_dir()+"html/fonts/" + static_resource, param.getFormParamList());
	}

}
